<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件</title>
</head>
<body>
<div id="app">
  <input type="text" v-model="val" @keyup.enter="add">
  <!--
    键盘修饰符
    <input type="text" v-model="val" @keyup.ctrl.enter="add">
    <input type="text" v-model="val" @keyup.enter="add">
  -->
  <ul>
    <li v-for="(value,index) in arrs" >
        {{value}} <button @click="del(index)">删除</button>
    </li>
  </ul>

</div>

</body>
<script src="../node_modules/vue/dist/vue.js"></script>
<script>
    // vue 提供v-for 解决循环问题 更高效 会复用原有结构
   let vm =  new Vue({
        el: '#app',
            methods:{ //methods中的this指向的都是实例
              add(e){
                console.log("do add",e.keyCode)
                // if(e.keyCode === 13){
                  console.log("回车")
                  this.arrs.unshift(this.val);
                  this.val='';
                // }
              },
              del(index){
                this.arrs = this.arrs.filter((item,i)=>i !== index)
              }
            },
            data:{
              val:'',
              arrs:[]
            }
    })


</script>
</html>
